<template>
    <div>
        <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>单位管理</el-breadcrumb-item>
      <el-breadcrumb-item>项目管理</el-breadcrumb-item>
    </el-breadcrumb>
        <el-card>

 <el-row>
<el-col :span="12"><el-button @click.native="addEventsDialogVisible=true">添加项目</el-button></el-col>

          </el-row>

 <el-table
    :data="eventsTableData"
    border
    style="width: 100%">
    
    <el-table-column
      prop="eventName"
      label="项目名称"
      width="120">
    </el-table-column>
    <el-table-column
      prop="eventCode"
      label="项目代号"
      width="120">
    </el-table-column>
   <el-table-column
      prop="eventRuleDesc"
      label="规则描述"
      width="1100">
    </el-table-column>
   <el-table-column
      fixed="right"
      label="操作"
      width="200">
      <template slot-scope="scope">
        <el-button @click="removeEvent(scope.row.id)">删除</el-button>
        <el-button >编辑</el-button>
      </template>
    </el-table-column> 
  </el-table>


        </el-card>
         <!-- 添加比赛 -->
        <el-dialog
  title="添加项目"
  :visible.sync="addEventsDialogVisible"
  width="50%"
  >
  <el-form
  :model="addEventsFrom"
  >
  
<el-form-item label="项目名称">
    <el-input v-model="addEventsFrom.eventName"></el-input>
  </el-form-item>
<el-form-item label="项目代号">
    <el-input v-model="addEventsFrom.eventCode"></el-input>
  </el-form-item>
  <el-form-item label="项目规则简介">
    <el-input type="textarea" v-model="addEventsFrom.eventRuleDesc"></el-input>
  </el-form-item>
 
</el-form>
  <span slot="footer" class="dialog-footer">
          <el-button @click="addEventsDialogVisible=false">取 消</el-button>
          <el-button type="primary" @click="addEvents()">确 定</el-button>
        </span>
</el-dialog>
    </div>
</template>
<style lang="less" scoped>
.el-card{
margin: 5px;


}


</style>
<script>
  export default {
    methods: {
      
      async getEvents(){
const { data: res } = await this.$http.get("match-event/getEvents")
 if (res.code !== 200) {
          this.$message.error("获取失败！");
        } 
        this.eventsTableData=res.data
        console.log(this.eventsTableData)
      },
      async addEvents(){

      const { data: res } = await this.$http.put("match-event/addEvent",
      {
eventName:this.addEventsFrom.eventName,
eventRuleDesc:this.addEventsFrom.eventRuleDesc,
eventCode:this.addEventsFrom.eventCode
      }
      
      )  ;
        if (res.code !== 200) {
          this.$message.error("添加失败！");
        } else if (res.code === 200) {
          this.$message.success("添加成功！");
          this.addEventsDialogVisible=false;
          this.getEvents();
        }


      }
,
async removeEvent(id){

    const { data: res } = await this.$http.put(`match-event/removeEvent?id=${id}`)
if (res.code !== 200) {
          this.$message.error("删除失败！");
        } else if (res.code === 200) {
          this.$message.success("删除成功！");
          
          this.getEvents();
        }

}


    },
created(){

  this.getEvents()
},
    data() {
      return {
        eventsTableData: [],
addEventsFrom:{
eventName:'',
eventRuleDesc:'',
eventCode:'',


},
addEventsDialogVisible:false,
      }
    }
  }
</script>